import Vue from 'vue'
import Vuex from 'vuex'
import router, {resetRouter} from "@/router";

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        currentPathName: '',
        user:localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")):null
    },
    mutations: {
        setUserInfo(state,user){
            console.log("更新user")
            state.user = user
        },
        setPath (state) {
           state.currentPathName = localStorage.getItem("currentPathName")
        },
        logout() {
            // 清空缓存
            localStorage.removeItem("user")
            localStorage.removeItem("menus")
            router.push("/login")

            // 并 重置路由
            resetRouter()
        }
    }
})

export default store
